package com.zhiyou.map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Set;

import com.zhiyou.set.People;

public class Demo1 {
	
	public static void main(String[] args) {
		
		/* map中的元素是无序 ,key不可以重复
		 * map中的元素是以键值对存放
		 * k:key   v:value   
		 * String   String
		 */
		
		HashMap<String, String> map = new HashMap<>();
		//param1:key  标记
		//param2:value 数据
		map.put("name1", "张三");
		map.put("name2", "李四");
		map.put("name3", "王五");
		map.put("name1", "赵四");
		map.put("name5", "赵四");
		System.out.println(map);
		
		//根据key获取对应元素
		String name2 = map.get("name2");
		System.out.println(name2);
		
		//获取到map中所有的key
		Set<String> keySet = map.keySet();
		System.out.println(keySet);
		
		//获取到map中的所有value值
		Collection<String> collection = map.values();
		System.out.println(collection);
		//是否包含某个key
		System.out.println(map.containsKey("name4"));
		System.out.println(map.containsValue("赵四"));
		
		//删除指定key对应的元素
		map.remove("name1");
		//清空map
		map.clear();
		System.out.println(map);
		
		
		
		HashMap<String, People> map2 = new HashMap<>();
		People p1 = new People("11", "aa", 22);
		map2.put("people1", p1);
		
		System.out.println(map2);
		
		
		//hashCode 
		HashMap<People, String> map3 = new HashMap<>();
		map3.put(p1, "zhangsan");
		People p2 = new People("11", "aa", 22);
		map3.put(p2,"lisi");
		System.out.println(map3);
		
	}

}
